﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoVanHocTapData.Infrastructure;
using CoVanHocTapData.Entities;
using CoVanHocTapData.Interface;

namespace CoVanHocTapData.Concretes
{
    public class SinhVienRepository : ISinhVienRepository
    {
        DangKyPhuEntities entities;


        public SinhVienRepository()
        {
            entities = new DangKyPhuEntities();
        }

        #region Repository

        #endregion

        public Entities.SinhVien LaySVDangNhap()
        {
            throw new NotImplementedException();
        }

        public SinhVien LaySVDangNhap(string strMSSV)
        {
            return (from m in entities.SinhViens
                    where m.MSSV.Equals(strMSSV)
                    select m).ToList().FirstOrDefault();
        }

        public SinhVien LaySVTuMaSV(string maSV)
        {
            return (from m in entities.SinhViens
                    where m.MSSV == maSV
                    select m).FirstOrDefault();
        }

        public float DiemTrungBinhTichLuyCua(string maSV)
        {

            throw new NotImplementedException();
        }

        public float? TinChiTichLuyCua(string maSV)
        {
            KetQuaHocRepository ketQuaRepo = new KetQuaHocRepository();
            var dsmhDaHoc = ketQuaRepo.DSMonHocTichLuy(maSV, 0);
            float? tongTC = 0;

            foreach (var kqh in dsmhDaHoc)
            {
                tongTC += kqh.MonHoc.SoDVHocTap;
            }
            return tongTC;
        }

        public float? TinChiTichLuyBatBuocCua(string maSV)
        {
            KetQuaHocRepository ketQuaRepository = new KetQuaHocRepository();
            var dsmhDaHoc = ketQuaRepository.DSMonHocTichLuy(maSV, 1);
            float? tongTC = 0;

            foreach (var kqh in dsmhDaHoc)
            {
                tongTC += kqh.MonHoc.SoDVHocTap;
            }
            return tongTC;
        }

        public float? TinChiTichLuyTuChonCua(string maSV)
        {
            KetQuaHocRepository ketQuaRepository = new KetQuaHocRepository();
            var dsmhDaHoc = ketQuaRepository.DSMonHocTichLuy(maSV, 2);
            float? tongTC = 0;
            foreach (var kqh in dsmhDaHoc)
            {
                tongTC += kqh.MonHoc.SoDVHocTap;
            }
            return tongTC;
        }

        public int DiemToeicDaHT(string maSV)
        {
            KetQuaHocRepository ketQuaRepository = new KetQuaHocRepository();
            var monAVGTCaoNhatDaHT = ketQuaRepository.LayMonAVGTCaoNhatDaHT(maSV);
            int maMonInt = Int32.Parse(monAVGTCaoNhatDaHT.MonHocID);
            switch (monAVGTCaoNhatDaHT.MonHocID)
            {
                case "001001": return 250;

                case "001002": return 300;

                case "001003": return 350;

                case "001004": return 400;

                case "001005": return 450;

                case "001006": return 999;

                default: return 0;
            }
        }

        public string DSMonAVGTDaHT(string maSV)
        {
            //KetQuaHocRepository ketQuaRepository = new KetQuaHocRepository();
            MonHocRepository monHocRepo = new MonHocRepository();
            var dsMonAVGTDaHT = monHocRepo.LayDanhSachAVGTDaHT(maSV);
            
            string dsmon = "";
            foreach (var mon in dsMonAVGTDaHT)
            {                
                dsmon += mon.MonHocID + " - " +mon.TenMonHoc  + "</br>";
            }
            return dsmon;
        }

        public string DSMonGDTCDaHT(string maSV)
        {
            MonHocRepository monHocRepo = new MonHocRepository();
            var dsMonDaHT = monHocRepo.LayDanhSachGDTCDaHT(maSV);
            string dsmon = "";
            foreach (var mon in dsMonDaHT)
            {
                dsmon += mon.MonHocID + " - " + mon.TenMonHoc + "</br>";
            }
            return dsmon;
        }

        public string DSMonGDQPDaHT(string maSV)
        {
            MonHocRepository monHocRepo = new MonHocRepository();
            var dsMonDaHT = monHocRepo.LayDanhSachGDQPDaHT(maSV);
            string dsmon = "";
            foreach (var mon in dsMonDaHT)
            {
                dsmon += mon.MonHocID + " - " + mon.TenMonHoc + "</br>";
            }
            return dsmon;
        }
    }
}
